package edu.tum.cs.stageflow.language.ui.views.schedule

import org.eclipse.jface.viewers.TreePath
import org.eclipse.jface.viewers.ViewerRow
import org.eclipse.swt.graphics.Color
import org.eclipse.swt.graphics.Font
import org.eclipse.swt.graphics.Image
import org.eclipse.swt.widgets.TableItem

class ScheduleTableViewerRow extends ViewerRow {
	private TableItem item;

	new(TableItem item) {
		this.item = item
	}

	override clone() {
		return new ScheduleTableViewerRow(item)
	}

	override getBackground(int columnIndex) {
		return item.getBackground(columnIndex)
	}

	override getBounds() {
		return item.getBounds()
	}

	override getBounds(int columnIndex) {
		return item.getBounds(columnIndex)
	}

	override getColumnCount() {
		item.getParent().getColumnCount()
	}

	override getControl() {
		item.getParent()
	}

	override getElement() {
		item.getData()
	}

	override getFont(int columnIndex) {
		return item.getFont(columnIndex)
	}

	override getForeground(int columnIndex) {
		return item.getForeground(columnIndex)
	}

	override getImage(int columnIndex) {
		return item.getImage(columnIndex)
	}

	def void setItem(TableItem item) {
		this.item = item
	}
	
	override getItem() {
		return item
	}

	override getNeighbor(int direction, boolean sameLevel) {
		throw new UnsupportedOperationException("TODO: auto-generated method stub")
	}

	override getText(int columnIndex) {
		return item.getText(columnIndex)
	}

	override getTreePath() {
		return new TreePath(#{item.getData()})
	}

	override setBackground(int columnIndex, Color color) {
		item.setBackground(columnIndex, color)
	}

	override setFont(int columnIndex, Font font) {
		item.setFont(columnIndex, font)
	}

	override setForeground(int columnIndex, Color color) {
		item.setForeground(columnIndex, color)
	}

	override setImage(int columnIndex, Image image) {
		var Image oldImage = item.getImage(columnIndex);
		if (oldImage != image) {
			item.setImage(columnIndex,image);
		}
	}

	override setText(int columnIndex, String text) {
		item.setText(columnIndex, if (text == null) "" else text)
	}

}
